package main.inte;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.MimeMessage;

import main.bean.Email;
import main.param.GlobalParam;

public class Smtp4send {
	
	public boolean sendEmail(Email e){
		Properties props = new Properties();
		props.put("mail.store.protocol", GlobalParam.SMTP);
		props.put("mail.smtp.host", GlobalParam.SMTP_URL);
		props.put("mail.pop3.port", GlobalParam.SMTP_PORT);
		Session sess = Session.getInstance(props);
		
		MimeMessage msg = new MimeMessage(sess);
		try {
			msg.setFrom(e.getFrom());
			msg.setRecipients(Message.RecipientType.TO, e.getReceive());
			msg.setSubject(e.getSubject());
			msg.setText(e.getText());
			Transport.send(msg,GlobalParam.ACCOUNT,GlobalParam.PASSWD);
		} catch (MessagingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			return false;
		}
		return true;
	}
}
